package Tech.yunjing.onlineStorage.controller;

import Tech.yunjing.onlineStorage.common.utils.BaseResult;
import Tech.yunjing.onlineStorage.common.utils.Constants;
import Tech.yunjing.onlineStorage.service.ResourcesService;
import com.wordnik.swagger.annotations.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by yo on 2016/6/23.
 */
@RestController
@RequestMapping("resources")
@Api(basePath = "/resources", value = "资源文件", description = "文件相关操作", produces = "application/json")
public class ResourcesController extends BaseController {

    private static Logger logger = Logger.getLogger(ResourcesController.class);

    @Autowired
    private ResourcesService resourceService;

    /**
     *
     * @return
     */
    @ApiOperation(value="list",notes="获取资源列表")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "String")})
    @ApiResponses(value = {
            @ApiResponse(code = Constants.FAIL, message = "unknown server errors"),
            @ApiResponse(code = Constants.SUCCESS, message = "请求成功") })
    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult findList(@RequestParam String token){
        logger.debug("find resource list");
        return sendResult(Constants.SUCCESS,"获取资源列表成功",resourceService.findList());
    }

    /**
     *
     * @return
     */
    @ApiOperation(value="delete",notes="删除资源")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "资源ID", required = true, dataType = "String")})
    @ApiResponses(value = {
            @ApiResponse(code = Constants.FAIL, message = "unknown server errors"),
            @ApiResponse(code = Constants.SUCCESS, message = "请求成功") })
    @RequestMapping(value = "delete",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult delete(){
        logger.debug("delete resources");
        resourceService.delete("");
        return sendResult(Constants.SUCCESS,"删除资源成功");
    }
}
